package trefliq.EJB.entities;

import java.io.Serializable;
import java.sql.Date;
import java.util.Collection;
import javax.persistence.*;

/**
 *
 * @author Eric
 * 
 * adam - added additional named queries
 */

@Entity
@NamedQueries({
    @NamedQuery(name = "findAllMovies", query = "SELECT m FROM Movie m"),
    @NamedQuery(name = "Movie.findById", query = "SELECT m FROM Movie m WHERE m.id = :id"),
    @NamedQuery(name = "Movie.findByTitle", query = "SELECT m FROM Movie m WHERE m.title = :title"),
    @NamedQuery(name = "Movie.findByDescription", query = "SELECT m FROM Movie m WHERE m.description = :description"),
    @NamedQuery(name = "Movie.findByReleaseyear", query = "SELECT m FROM Movie m WHERE m.release = :release")})
public class Movie implements Serializable {
    //adam changes
    private static final long serialVersionUID = 1L;    
    @Id
    @Basic(optional = false)
//    @NotNull
    @Column(name = "ID", nullable = false)
    @GeneratedValue(strategy = GenerationType.AUTO)
//    @Column(name = "ID", nullable = false)
//    @GeneratedValue(strategy=GenerationType.TABLE, generator="MOVIE")
    private Long id;
    
    @Column(nullable=false)
    private String title;
    
    @Column(length=2000)
    private String description;
    
//    private String genre; //Adam took this out
    
    //private Rating rating;
    private Long rating;
    
    private Date release;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "movieid")
    private Collection<CartItem> cartItemCollection;
    
    public Movie() {
    }
    
    public Movie(Long id) {
        this.id = id;
    }
    
    public Movie(Long id, String title) {
        this.id = id;
        this.title = title;
    }
    
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public String getTitle() {
        return title;
    }
    
    public void setTitle(String title) {
        this.title = title;
    }
    
    public String getDescription() {
        return description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
   
    /* Adam took this out
    public String getGenre() {
        return genre;
    }
    
    public void setGenre(String genre) {
        this.genre = genre;
    }
    * /
    */
    /*
    public Rating getRating() {
        return rating;
    }
    
    public void setRating(Rating rating) {
        this.rating = rating;
    }
    */
    
    public Long getRating() {
        return rating;
    }
    
    public void setRating(Long rating) {
        this.rating = rating;
    }
    
    public Date getRelease() {
        return release;
    }
    
    public void setRelease(Date release) {
        this.release = release;
    }

    public Collection<CartItem> getCartItemCollection() {
        return cartItemCollection;
    }

    public void setCartItemCollection(Collection<CartItem> cartItemCollection) {
        this.cartItemCollection = cartItemCollection;
    }
        
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Movie)) {
            return false;
        }
        Movie other = (Movie) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "trefliq.persistence.entity.Movie[ id=" + id + " ] title[" + title +"]";
    }
}